//
//  StatusCellRetweetedView.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/21.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellRetweetedView: UIView {
    var bottomConstraint : Constraint?

    
    var retweeted_status : Status? {
        didSet{
            
            retweetedLabel.text = retweeted_status?.text
            pictureView.imageURLs = retweeted_status?.imageURLs
            
            self.bottomConstraint?.uninstall()
            if let urls = retweeted_status?.imageURLs {
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint =  make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
            }else {
                self.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomConstraint =  make.bottom.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin).constraint
                    
                })
            }
            
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = UIColor(white: 0.9, alpha: 1)
        addSubview(retweetedLabel)
        addSubview(pictureView)
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top).offset(StatusCellMargin)
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweetedLabel.snp_left)
            make.top.equalTo(retweetedLabel.snp_bottom).offset(StatusCellMargin)
            
        }
   
        self.snp_makeConstraints { (make) -> Void in
        self.bottomConstraint = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
        }
    
    }
    
    private lazy var retweetedLabel : UILabel = UILabel(title: "天外划过一颗流星，那景是如此的迷人", fontSize: 14, color: UIColor.darkGrayColor(), margin: StatusCellMargin)
    private lazy var pictureView : StatusCellPictureView = StatusCellPictureView()
    
    
}
